package fy.mdm.operator;

import com.seeyon.v3x.services.flow.bean.FlowExport;
import com.seeyon.v3x.services.form.bean.ValueExport;
import fy.form.listen.operate.AForm_Save_Operator;
import fy.form.listen.operate.IFormOperator;
import fy.mdm.bean.NewCodeBean;
import fy.mdm.dao.NewCodeDao;


import java.text.SimpleDateFormat;
import java.util.Date;

public class NewCodeOperator extends AForm_Save_Operator implements IFormOperator {
    private NewCodeBean bean = new NewCodeBean();
    @Override
    public String getFormName() {
        // TODO Auto-generated method stub
        return "新增客户代码申请";
    }
    @Override
    protected void parseOtherField_FirstStep(FlowExport flowExport) {
        // TODO Auto-generated method stub
        bean.setSummaryId(super.formBean.getSummaryId());
        bean.setBillname(flowExport.getFlowTitle());
        bean.setApplier(flowExport.getFlowCreatePerson().getId());
        bean.setTs(flowExport.getFlowCreateTime());
    }
    @Override
    protected void parseValueExport(ValueExport ve) {
        // TODO Auto-generated method stub
        String fieldName = ve.getDisplayName();
        if ("客户编码1".equals(fieldName)) {
            bean.setCUSTOMER_CODE(ve.getValue());
        }else if ("客户名称".equals(fieldName)) {
            bean.setCUSTOMER_NAME(ve.getValue());
        }else if ("客户类型".equals(fieldName)) {
            bean.setCUSTOMER_STYLE(ve.getValue());
        }else if ("客户代码".equals(fieldName)) {
            bean.setCUSTOMER_SHORT_NAME(ve.getValue());
        }else if ("客户类别".equals(fieldName)) {
            bean.setCUSTOMER_CATEGORY(ve.getValue());
        }else if ("地区".equals(fieldName)) {
            bean.setAREA(ve.getValue());
        }
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        bean.setAPPROVER_TIME(format);
    }
    @Override
    protected boolean save() {
        // TODO Auto-generated method stub
        try {
            NewCodeDao newCodeDao = new NewCodeDao();
            newCodeDao.setNewCodeBean(bean);
            return newCodeDao.StateReturn();
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }finally {

        }
        return success;

    }
}
